import yang from "./index.module.css"
// import "./index.css"
import React, { Component } from 'react'
import Background from '../../assets/bg9.jpg'
import {Link} from "react-router-dom"
import {getlogin} from '../../api/login'

var sectionStyle = {
    width: "100%",
    height: "100%",
    background: `url(${Background}) no-repeat center center fixed`, 
    backgroundSize: 'cover'
};
export default class Login extends Component {
    constructor(props) {
        super(props); 
        this.state={
            zhanghao:"",
            mima:""
        }
    }
    shangxiang(ev,asd){
        // console.log(ev)
        // console.log(asd)
        if(asd == "zhanghao"){
            this.setState({
                zhanghao:ev
            })
        }else{
            this.setState({
                mima:ev
            })
        }
    }
    denglu(){
        if(!this.state.zhanghao){
            alert("请输入账号")
            return;
        }
        if(!this.state.mima){
            alert("请输入密码")
            return;
        }
        getlogin({
            urename:this.state.zhanghao,
            password:this.state.mima
        }).then((ear)=>{
            if(ear.data == "dui"){
                sessionStorage.setItem("key",this.state.zhanghao)
                this.props.history.push({pathname:'/shou',state:{key:this.state.zhanghao}})
            }else{
                alert("没有该用户")
            }
        })
    }
    render() {
        return (
            <div className={yang.box} style={sectionStyle} >
                {/* <img src="./bg9.jpg" alt="" /> */}
                <div className={yang.logebox}>
                    <div className={yang.top}>
                        <img src="./logo.png" alt="" className={yang.img} />投资公司
                    </div>
                    <input type="text" placeholder="请输入账号" className={yang.input} value={this.state.zhanghao} onChange={(ev)=>this.shangxiang(ev.target.value,"zhanghao")}/>
                    <input type="password" placeholder="请输入密码" className={yang.input} value={this.state.mima} onChange={(ev)=>this.shangxiang(ev.target.value,"mima")} />
                    {/* <Link to='/shou'>  */}
                        <button className={yang.button} onClick={()=>this.denglu()}>登录</button> 
                    {/* </Link> */}
                    <li className={yang.li}>温馨提示：请阅读文档后在进行登录</li>
                </div>
            </div>
        )
    }
}
